package com.albert;

import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
public class TimeTest3 {
    public static void main(String[] args) {
        //String inputTime = "2024-10-28T01:18:49.2430114Z";
        String inputTime = "2024-10-28T01:18:49.243Z";
        //String inputTime = "2024-10-28T01:18:49Z";
        DateTimeFormatter inputFormatter = null;
        log.info("时间字符串长度:"+inputTime.length());
        if(inputTime.length()==28) {
            inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'").withZone(ZoneId.systemDefault());
        } else if (inputTime.length()==24) {
            inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").withZone(ZoneId.systemDefault());
        } else if (inputTime.length()==20) {
            inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'").withZone(ZoneId.systemDefault());
        }
        ZonedDateTime zonedDateTime = ZonedDateTime.parse(inputTime, inputFormatter);
        DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
        LocalDateTime plus8Hours = localDateTime.plusHours(8);
        String formattedTime = plus8Hours.format(outputFormatter);

        System.out.println(formattedTime);
    }
}
